package com.app.ui.activity.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.app.ui.dialog.DialogCustomWaiting;
import com.retrofits.net.common.RequestBack;

import java.io.Serializable;

/**
 * Created by Administrator on 2016/9/7.
 */
public class BaseActivity extends AppCompatActivity implements RequestBack {
    protected BaseApplication baseApplication;
    private DialogCustomWaiting dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseApplication = (BaseApplication) getApplication();
    }

    private Intent it;
    private Bundle bundle;

    //arg0,   arg1
    protected String getStringExtra(String key) {
        if (it == null) {
            it = getIntent();
        }
        return it.getStringExtra(key);
    }

    protected Serializable getObjectExtra(String key) {
        if (it == null) {
            it = getIntent();
        }
        if (bundle == null) {
            bundle = it.getExtras();
        }
        if (bundle == null) {
            return null;
        }
        Serializable bean = bundle.getSerializable(key);
        return bean;
    }
    private InputMethodManager imm;

    protected void setInputMethod(boolean isShow, View view) {
        if (imm == null) {
            imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        }
        if (isShow) {
            imm.showSoftInput(view, 0);
        }
        if (!isShow) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
    protected void dialogShow() {
        if (dialog == null) {
            dialog = new DialogCustomWaiting(this);
        }
        dialog.show();
    }

    protected void dialogDismiss() {
        if (dialog == null) {
            return;
        }
        dialog.dismiss();
    }
    @Override
    public void OnBack(int what, Object obj, String msg, String other) {

    }
    public class TextChangeListener implements TextWatcher {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            BaseActivity.this.beforeTextChanged(s, start, count, after);
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            BaseActivity.this.onTextChanged(s, start, before, count);

        }

        @Override
        public void afterTextChanged(Editable s) {
            BaseActivity.this.afterTextChanged(s);
        }
    }


    protected void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    protected void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    protected void afterTextChanged(Editable s) {

    }
}
